import store from '@/store';
import {
  login
} from '@/api/login'

export const reRefrash_token = ({
  id = store.getters.id,
  username = store.getters.username,
  nick_name = store.getters.token.nick_name,
  user_birth = store.getters.token.user_birth,
  password = store.getters.token.password,
  user_photo = store.getters.token.user_photo,
  user_phone = store.getters.token.user_phone,
  user_sex = store.getters.token.user_sex
}) => {
  // console.log(id);
  return {
    id,
    username,
    password,
    nick_name,
    user_birth,
    user_photo,
    user_phone,
    user_sex
  }
}

export const checkUsername = async (val) => {
  // 获取所有最新的用户信息
  const res = await login({
    username: val
  });
  // 判断注册的用户名和是否重复
  return !res.some((x) => {
    return x.username === val;
  });
}
